package com.sina.shop.domain.carousel;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.sina.shop.core.domain.Domain;
import com.sina.shop.domain.Status;
import com.sina.shop.util.FileSizeChangeUtil;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.sql.Update;

import javax.persistence.*;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * Created with IntelliJ IDEA.
 * Description: 用于记录分片上传的文件信息
 * 段浩杰   2017-11-22-12:01
 */
@Entity
@Table(name = "tb_carousel")
@DynamicUpdate
@DynamicInsert
public class Carousel extends Domain implements Serializable {

    @Id
    @Column(name = "id", updatable = false)
    @GenericGenerator(name = "sequence_id", strategy = "com.sina.shop.sequence.IdGenerator")
    @GeneratedValue(generator = "sequence_id")
    @Min(1)
    @NotNull(groups = {Update.class})
    private Long id;//id

    @Column(name = "localDateTime", updatable = false)
    @JsonSerialize(using = LocalDateTimeSerializer.class)//此注解是为了解决feign远程调用中出现的LocalDateTime不能序列化问题
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime localDateTime;//上传时间

    @Column(name = "name")
    private String name;//上传用户

    @Column(name = "originalFileName")
    private String originalFileName;//原文件名字

    @Column(name = "storageFileName")
    private String storageFileName;//存储文件名字

    @Column(name = "cloudStorageAddress")
    private String cloudStorageAddress;//云存储地址

    @Column(name = "fileSize")
    private Long fileSize;//文件大小

    @Enumerated(EnumType.STRING)
    @Column(name = "status")
    private Status status;//文件状态用来标记性删除

    /*@Column(name = "sort")
    private Integer sort;*/

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getLocalDateTime() {
        return localDateTime;
    }

    public void setLocalDateTime(LocalDateTime localDateTime) {
        this.localDateTime = localDateTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOriginalFileName() {
        return originalFileName;
    }

    public void setOriginalFileName(String originalFileName) {
        this.originalFileName = originalFileName;
    }

    public String getStorageFileName() {
        return storageFileName;
    }

    public void setStorageFileName(String storageFileName) {
        this.storageFileName = storageFileName;
    }

    public String getCloudStorageAddress() {
        return cloudStorageAddress;
    }

    public void setCloudStorageAddress(String cloudStorageAddress) {
        this.cloudStorageAddress = cloudStorageAddress;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public String getPrintSize() {
        return FileSizeChangeUtil.getPrintSize(fileSize);
    }
}
